<template>
  <button
    class="ep-button"
    :class="[
      `ep-button-${type}`,
      `ep-button-${size}`,
      {
        'ep-button-icon': icon,
        'ep-button-round': round,
        'ep-button-disabled': disabled,
      },
    ]"
    :disabled="disabled"
    @click="clickHandler"
  >
    <img v-if="icon" :src="iconSrc" alt="" />
    <!-- $slots.default：可以得到使用的插槽 -->
    <span v-if="$slots.default"> <slot></slot></span>
  </button>
</template>

<script>
export default {
  name: "epButton",
  props: {
    type: {
      type: String,
      default: "primary",
    },
    size: {
      type: String,
      default: "normal",
    },
    round: {
      type: Boolean,
      default: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    icon: {
      type: String,
    },
  },

  computed: {
    iconSrc() {
      if (this.icon) {
        return require(`@/assets/img/${this.icon}`);
      }
    },
  },
  methods: {
    clickHandler(e) {
      this.$emit("click", e);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.ep-button {
  position: relative;
  display: inline-block;
  padding: 0 8px;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  cursor: pointer;
  img {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translate(0, -50%);
    width: 24px;
    height: auto;
    vertical-align: middle;
  }
  span {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 8px;
  }
  &-primary {
    border: 1px solid #2175A9;
    background: #002A44;
  }
  &-rank {
    border: 1px solid #2175A9;
    background: #002A44;
    color: #49bbeb;
  }
  &-danger {
    border: 1px solid #8e1515;
    background: #460606;
  }
  &-back {
    border: none;
    background: #0f2b3e;
    color: #49bbeb;
    padding: 0 15px;
  }
  &-save {
    border: none;
    background: #49BBEB;
    padding: 0 15px;
  }
  &-large {
    height: 42px;
    line-height: 42px;
    font-size: 18px;
  }
  &-normal {
    height: 36px;
    line-height: 36px;
    font-size: 16px;
  }
  &-small {
    height: 30px;
    line-height: 30px;
  }
  &-round {
    border-radius: 5px;
  }
  &-icon {
    padding-left: 29px;
  }
}
</style>
